<?php

namespace App\Repository\Main;

use App\Repository\BaseRepository;
use App\Repository\StockMain\GoodsOrderRepostition;
use App\Repository\UpThree\DouYinOrderRepostition;
use App\Repository\UpThree\GetThreeOrderRepostition;
use App\Repository\UpThree\MainOrderRepostition;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Logger;


class MainRepository extends BaseRepository
{
    public function __construct()
    {
        $this->log = new Logger('mainOrder');
        $this->log->pushHandler(
            (new RotatingFileHandler(storage_path('/logs/mainOrder.log'), 14, Logger::DEBUG, true, 0777))->setFormatter(new LineFormatter(null, null, true, true))
        );
        parent::__construct();
    }

    private $log = null;

    //异步信息 全部都需要走这个地方
    public function sendOrder($data = [], $type = '')
    {
        if (empty($type)) {
            return ['code' => 100, 'msg' => 'type 为空'];
        }
        if (empty($data)) {
            return ['code' => 101, 'msg' => '数据为空'];
        }
        $res = [];
        switch ($type) {
            case 'createOrder':
                // 提交上游生产的数据
                $model = new MainOrderRepostition();
                $res = $model->orderThree($data, false);
                break;
            case 'catchOrder':
                // height  抓取数据 然后直接提交到第三方
                $model = new GetThreeOrderRepostition();
                $res = $model->getOrder($data);
                break;
            case 'catchOrderDouYin':
                // height  抓取数据 然后直接提交到第三方
                $model = new DouYinOrderRepostition();
                $res = $model->getDouYinOrders($data);
                break;
            case 'postCatchOrder':
                // height  抓取数据 然后直接提交到第三方
                $model = new DouYinOrderRepostition();
                $res = $model->postCatchOrder($data);
                break;
            case 'catchKwaiOrder':
                break;
            case 'smsAndPushOrder':
                // 短信发送和推送数据
                $model = new MainOrderRepostition();
                $res = $model->isSmsAndPush($data);
                break;
            case 'replySms':
                // 短信回复信息
                $model = new MainOrderRepostition();
                $res = $model->replySms($data);
                break;
            case 'missOrderDouyin':
                //抖音漏单抓取  抖音跑单查询出来的数据  然后提交到抓单表中
                $model = new GetThreeOrderRepostition();
                $res = $model->getMissingOrder($data);
                break;
            case 'batchAllGoods':
                // 商品重新提交
                $model = new MainOrderRepostition();
                $res = $model->batchAllOrderThree($data);
                break;
            case 'douyinNewSubmit':
                // 抖音抓单批量修改商品或提交的
                $model = new GetThreeOrderRepostition();
                $res = $model->douyinNewSubmit($data);
                break;
            case 'pddNewSubmit':
                //pddNewSubmit
                $model = new GetThreeOrderRepostition();
                $res = $model->pddNewSubmit($data);
                break;
            case 'sendSms':

                if (empty($data['data'])) {
                    $res = ['statsu' => 100, 'msg' => '延时发送短信订单参数为空'];
                    break;
                }
                if (empty($data['confData'])) {
                    $res = ['statsu' => 100, 'msg' => '延时发送短信配置参数为空'];
                    break;
                }
                $model = new MainOrderRepostition();
                $datas = $data['data'];
                $resConf = $data['confData'];
                $res = $model->isSmsAndSend($datas, $resConf);
                break;
            case 'sendGoodsZ':
                if (empty($data['data'])) {
                    $res = ['statsu' => 100, 'msg' => '延时转单订单参数为空'];
                    break;
                }
                if (empty($data['confData'])) {
                    $res = ['statsu' => 101, 'msg' => '延时转单配置参数为空'];
                    break;
                }
                $model = new MainOrderRepostition();
                $datas = $data['data'];
                $resConf = $data['confData'];
                $res = $model->isGoodsAndSend($datas, $resConf);
                break;
            case 'informationSyncOrders':
                // 同步订单 信息流表里面的数据同步到订单表里
                $model = new GoodsOrderRepostition();
                $res = $model->syncOrders($data);
                break;
        }
        $this->log->info('类型:' . $type . '参数:' . jsonEncodeMsg($data) . '返回的结果:' . jsonEncodeMsg($res));
        // 这边可添加重复操作 条件未定 所以先空留
        return $res;
    }
}
